<?php
require_once("DatabaseConnect.php");
require_once("authenticate.php"); //ensure logged in to access
//conntion to databse
$con=Remoteconnect();
if($con==null){

	$con=Localconnect();	
}


switch ($_REQUEST['submit']){
case "Add":

$Email=$_SESSION['email'];
$sql="INSERT INTO `strategies` (`Name`, `Email`, `Buy1_1`, `Buy1_2`, `Buy1_3`, `Sell1_1`, `Sell1_2`, `Sell1_3`, `BuyInput1_1`, `BuyInput1_2`, `BuyInput1_3`, `SellInput1_1`, `SellInput1_2`, `SellInput1_3`) VALUES ('$_POST[Name]', '$Email', '$_POST[Buy1_1]', '$_POST[Buy1_2]', '$_POST[Buy1_3]', '$_POST[Sell1_1]', '$_POST[Sell1_2]', '$_POST[Sell1_3]', '$_POST[BuyInput1_1]', '$_POST[BuyInput1_2]', '$_POST[BuyInput1_3]', '$_POST[SellInput1_1]', '$_POST[SellInput1_2]', '$_POST[SellInput1_3]')";



//Run query and create feedback message
if (!mysqli_query($con,$sql))
{
  $_SESSION['FeedbackBad']='Error: ' . mysqli_error($con);
}else{
$_SESSION['FeedbackGood']="Successfully added $_POST[Name] to database of strategies";
}


break;

case "Edit":

$Email=$_SESSION['email'];
$sql="Update `strategies` SET `Buy1_1`='$_POST[Buy1_1]', `Buy1_2`='$_POST[Buy1_2]', `Buy1_3`='$_POST[Buy1_3]', `Sell1_1`='$_POST[Sell1_1]', `Sell1_2`='$_POST[Sell1_2]', `Sell1_3`='$_POST[Sell1_3]' WHERE `Email`='$Email' AND `Name`='$_POST[Name]'";

//Run query and create feedback message
if (!mysqli_query($con,$sql))
{
  $_SESSION['FeedbackBad']='Error: ' . mysqli_error($con);
}else{
$_SESSION['FeedbackGood']="Successfully updated $_POST[Name] to database of strategies";
}



break;

case "Delete":

$Email=$_SESSION['email'];
$sql = "DELETE FROM `strategies` WHERE `Email`='$Email' AND `Name`='$_POST[Name]'";

//Run query and create feedback message
if (!mysqli_query($con,$sql))
{
  $_SESSION['FeedbackBad']='ErrorLOL: ' . mysqli_error($con);
}else{
$_SESSION['FeedbackGood']="Successfully Deleted $_POST[Name] from database of strategies";
}


break;
}
header("Location: /Demo/stockMonitoring.php");

?>